//
//  UIViewController+MLRemoveNavigationBarBackTitle.m
//  MLRemoveNavBackTitle
//
//  Created by molon on 16/3/20.
//  Copyright © 2016年 molon. All rights reserved.
//

#import "UIViewController+MLRemoveNavigationBarBackTitle.h"
#import <objc/runtime.h>

@implementation UIViewController (MLRemoveNavigationBarBackTitle)

+ (void)validateMLRemoveNavigationBarBackTitle
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        Class c = [self class];
        Method origMethod = class_getInstanceMethod(c, @selector(viewDidLoad));
        Method newMethod = class_getInstanceMethod(c, @selector(__ml_hook_removeBackTitle_viewDidLoad));
        if (origMethod&&newMethod) {
            method_exchangeImplementations(origMethod, newMethod);
        }
    });
}

- (void)__ml_hook_removeBackTitle_viewDidLoad
{
    UIBarButtonItem *backButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
    [self.navigationItem setBackBarButtonItem:backButtonItem];
    
    [self __ml_hook_removeBackTitle_viewDidLoad];
}

@end
